package org.example;

import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws InterruptedException {
//        System.out.println("Hello world!");
//        List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd", "", "jkl");
//        Stream<String> stream = strings.stream().map(String::toUpperCase);
//        List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
//        strings.stream().filter(string -> !string.isEmpty()).forEach(x -> System.out.println(x));

//        System.out.println("Stream: " + stream.count());
//        System.out.println("Filtered List: " + filtered);
        Main main = new Main();
        main.testFlux();
    }

    public void testFlux() throws InterruptedException {
        System.out.println("初始化网络管理器");
//        Duration duration = Duration.ofSeconds(10);
//        System.out.println(duration.getSeconds());
//        Flux.interval(Duration.ofSeconds(3)).subscribe(t -> System.out.println(t));

//        Flux.interval(Duration.ofSeconds(3)).subscribe(System.out::println);
//        TimeUnit.MINUTES.sleep(30);

//        Iterable<String> iterable = Arrays.asList("foo", "bar", "baz");
//        Flux<String> flux = Flux.fromIterable(iterable);
//        flux.subscribe(System.out::println);


        HashMap<String, String> hashMap = new HashMap<String, String>() {{
            put("foo", "bar");
            put("foo2", "bar2");
        }};
        HashMap<String, String> hashMap2 = new HashMap<String, String>() {{
            put("foo3", "bar3");
            put("foo4", "bar4");
        }};
        Iterable<HashMap<String, String>> iterable = Arrays.asList(hashMap, hashMap2);
        Flux<HashMap<String, String>> flux = Flux.fromIterable(iterable);
//        flux.flatMapIterable(x -> {
//            ArrayList<String> string = new ArrayList<>();
//            x.forEach((k, v) -> {
//                string.add(v);
//            });
//            return string;
//        }).subscribe(x -> {
//            System.out.println(x);
//        });
//        flux.flatMap(x -> {
//            ArrayList<String> string = new ArrayList<>();
//            x.forEach((k, v) -> {
//                string.add(v);
//            });
//            return Flux.fromIterable(string);
//        }).subscribe(x -> {
//            System.out.println(x);
//        });
//        flux.subscribe(x -> {
//            System.out.println(x);
//        });
    }

    public void test() {
        System.out.println("test");
    }
}

